<?php
namespace app\admin\controller;
use think\Request;

class Admin extends Base{

    function __construct(Request $request = null)
    {
        parent::__construct($request);
        $admin = model('admin')->where('id',$this->uid)->find();
        if($admin->isAdmin != 1){
           $this->redirect('common/errorAuthority');
           die;
        }

    }



    public function admin(){


        $admins = model('admin')->order('id desc')->select();
        $this->assign('admins',$admins);
        return view('admin');
    }


    public function changePassword($uid){

        $user = model('user')->where('id',$uid)->find();
        $this->assign('user',$user);
        return view('changePassword');

    }




    public function doChangePassword(){
        $uid = Request::instance()->post('uid');
        $pwd = Request::instance()->post('password');
        model('admin')->changePwd($uid,$pwd);
        $this->redirect('admin');
    }


    public function addAdmin(){

        return view('addAdmin');

    }

    public function saveAdmin(){
        $data = Request::instance()->post();
        $img = Request::instance()->file('img');
        model('admin')->saveAdmin($data,$img);
        $this->redirect('admin');
    }

    public function updateInfo($uid){

        $user = model('admin')->where('id',$uid)->find();
        $this->assign('user',$user);
        return view('updateInfo');

    }


    public function deleteAdmin($id){

        model('admin')->where('id',$id)->delete();
        $this->redirect('admin');

    }







}